//
//  UIImagView+TapGesture.m
//  template_test
//
//  Created by stone on 16/9/8.
//  Copyright © 2016年 stone. All rights reserved.
//

#import "UIImageView+TapGesture.h"

@implementation UIImageView (TapGesture)

- (SNTapGestureRecognizerBlock)sn_tapBlock {
    return objc_getAssociatedObject(self, _cmd);
}

- (void)setSn_tapBlock:(SNTapGestureRecognizerBlock)sn_tapBlock {
    objc_setAssociatedObject(self, @selector(sn_tapBlock), sn_tapBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActived:)];
    [self addGestureRecognizer:tap];

}
- (void)tapActived:(UITapGestureRecognizer *)sender {
    NSLog(@"%s", __func__);

    if (self.sn_tapBlock) {
        self.sn_tapBlock();
    }
}
@end

@implementation UIView (TapGesture)

- (SNTapGestureRecognizerBlock)sn_tapBlock {
    return objc_getAssociatedObject(self, _cmd);
}

- (void)setSn_tapBlock:(SNTapGestureRecognizerBlock)sn_tapBlock {
    objc_setAssociatedObject(self, @selector(sn_tapBlock), sn_tapBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActived:)];
    [self addGestureRecognizer:tap];
    
}
- (void)tapActived:(UITapGestureRecognizer *)sender {
    NSLog(@"%s", __func__);
    
    if (self.sn_tapBlock) {
        self.sn_tapBlock();
    }
}
@end
